﻿using LoveEat.API.Write.Applications.Commands.slaughter;
using LoveEat.Domain.slaughter;
using LoveEat.ErrorCode;
using LoveEat.Infrastructure.Interfaces;
using MediatR;

namespace LoveEat.API.Write.Applications.CommandHandlers.slaughter
{
    public class AddCompCommandHandler : IRequestHandler<AddCompCommand, APIResult<int>>
    {
        private readonly IBaseRespository<CompModel> compRep;

        public AddCompCommandHandler(IBaseRespository<CompModel> compRep)
        {
            this.compRep = compRep;
        }

        public async Task<APIResult<int>> Handle(AddCompCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result=new APIResult<int>();
            result.Code=APIResultCode.添加成功;
            result.Message=APIResultCode.添加成功.ToString();

            CompModel comp=new CompModel();
            comp.ComName=request.ComName;
            comp.ComAdds=request.ComAdds;
            comp.ComTime=request.ComTime;
            comp.ComInt=request.ComInt;
            comp.IsDelete = false;
            await compRep.AddAsync(comp);


            return await Task.FromResult(result);
        }
    }
}
